// userSignAPI.ts
import { request } from "../utils/request";

/**
 * 用户签到（当天）
 * @param userId 用户ID
 * @returns 响应格式：{code:200, msg:"ok", data: true/false}
 */
export const signUserIn = (userId: number | string) => {
    return request({
        method: 'POST',
        url: `/userSign/${userId}` // 正确路径：/userSign/{userId}
    });
};

/**
 * 用户补签（指定日期）
 * @param userId 用户ID
 * @param date 日期（yyyy-MM-dd）
 * @returns 响应格式：{code:200, msg:"ok", data: true/false}
 */
export const signUserHistory = (userId: number | string, date: string) => {
    return request({
        method: 'POST',
        url: `/userSign/${userId}/history`, // 正确路径：/userSign/{userId}/history
        params: { date }
    });
};

/**
 * 获取用户某月签到状态（布尔数组）
 * @param userId 用户ID
 * @param year 年份
 * @param month 月份
 * @returns 响应格式：{code:200, msg:"ok", data: [false, true, ...]}
 */
export const getSignedStatusByMonth = (userId: number | string, year: number, month: number) => {
    return request({
        method: 'GET',
        url: `/userSign/${userId}/status?year=${year}&month=${month}`, // 正确路径：/userSign/{userId}/status
        params: {
            year: year.toString(), // 确保参数为字符串类型，避免后端解析问题
            month: month.toString()
        }
    });
};

/**
 * 获取用户连续签到天数
 * 
 * @param userId 用户ID
 * @returns 响应格式：{"code": 200,"msg": "ok","data": 0}
 */
export const getContinuousSignDays = (userId: number | string) => {
	return request({
		method: 'GET',
		url: `/userSign/${userId}/continuous`, // 接口路径：/userSign/{userId}/continuous
	})
};

/**
 * 获取用户某月总签到次数
 * 
 * @param userId 用户ID
 * @param year 年份
 * @param month 月份
 * @returns 响应格式：{"code": 200,"msg": "ok","data": 3}
 */
export const getTotalSignCount = (userId: number | string, year: number, month: number) => {
	return request({
		method: 'GET',
		url: `/userSign/${userId}/count?year=${year}&month=${month}`, // 接口路径：/userSign/{userId}/count
	})
};